﻿//判断是否记住密码，记住密码的话，从localstorage里取账号密码
var remember = false;
var userid = "";
var password = "";
var mbf;
var app = angular.module('myLogin', []);
try{
	mbf = JSON.parse(localStorage.getItem("mbf"));
	remember = mbf.remember;
	userid = mbf.userid;
	password = mbf.password;
}catch(e){
}
app.controller('myLoginCtrl', function($scope) {
$scope.user = {userid:userid, password:password,remember:remember};
$scope.info = "";
$scope.login = function(){
	//---------------------------16/04/17   樊-------------------------------
	//----------增加了前台页面的js判断，用户名密码等的输入格式规范-----------
	//-----------------------------------------------------------------------
	//重置div显示值
	$scope.info = "";
	//判断用户名是否为空                       
	if(/^$/.test($scope.user.userid)){
		$scope.info = "请输入用户名！";
		return false;
	}
	//判断用户名是否数字                       
	if(isNaN($scope.user.userid)){
		$scope.info = "用户名格式不正确！";
		return false;
	}	
	//判断用户名是否为11位                   
	if($scope.user.userid.length!=11){
		$scope.info = "请输入正确的手机号格式！";
		return false;
	}
	//判断密码是否为空                       
	if(/^$/.test($scope.user.password)){
		$scope.info = "请输入密码！";
		return false;
	}
	//---------------------------------以上-----------------------------------
	// 如果勾选了保存密码
	if($scope.user.remember){
		var rem = {"userid":$scope.user.userid,"password":$scope.user.password,"remember":$scope.user.remember};
		localStorage.setItem("mbf",JSON.stringify(rem));		
	}else{
		localStorage.clear();
	}
	login($scope.user.userid,$scope.user.password,function(result){
		if(!result.result){
			$scope.info = "用户名或密码错误！！！";
		}else{
			sessionStorage.setItem('userid',result.data[0].userid);
			sessionStorage.setItem('username',result.data[0].username);
			window.location.href = 'main';
		}
		
	});
};
});